<?php


namespace api\models;


use Faker\Provider\Uuid;

class Token extends \common\models\Token
{

    /**
     * 获取token
     * @return string
     * @throws \Throwable
     * @throws \yii\base\Exception
     */
    public function getTokenId(){
        $this->access_token = $this->generateAccessToken();
        $this->refresh_token = $this->generateRefreshToken();
        $this->token_id = Uuid::uuid();
        $this->insert(false);
        return $this->token_id;
    }

    /**
     * 生成令牌
     * @return string
     * @throws \yii\base\Exception
     */
    public function generateAccessToken(){
        return \Yii::$app->security->generateRandomString().'_'.time();
    }

    /**
     * 生成刷新令牌
     * @return string
     * @throws \yii\base\Exception
     */
    public function generateRefreshToken(){
        return \Yii::$app->security->generateRandomString().'_'.time();
    }
}